package demo7.CallCenter;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.ArrayBlockingQueue;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CallProcess {
    public CallCenter callCenter;

    public   static ArrayBlockingQueue<Event> queue = new ArrayBlockingQueue<>(100);
    public void dispatchCall(Event event) {
        CallCenter.Operator freeOperatorImmediately = callCenter.getFreeOperatorImmediately();
        CallCenter.Director freeDirectorImmediately=null;
        CallCenter.Manager freeManagerImmediately=null;
        if (freeOperatorImmediately != null && freeOperatorImmediately.handle(event)) {

        } else if((freeDirectorImmediately = callCenter.getFreeDirectorImmediately())!=null && freeDirectorImmediately.handle(event)) {

        }else if((freeManagerImmediately = callCenter.getFreeManagerImmediately())!=null){
            freeManagerImmediately.handle(event);
        }else {
            // put the queue ,
            queue.offer(event);
        }

    }
}